import Loading from "../components/loading";
import React,{Suspense} from "react";

const HOC=(props:{href:string})=>{
    //把权限获取出来
    const power = JSON.parse(sessionStorage.getItem('power') || '{}');
    //是否有权限
    let isPower = false;
    let Com:React.LazyExoticComponent<React.ComponentType<any>> | null;
    Com=null;
    if(power){
        for (let i = 0; i < power.length; i++) {
            
            if (power[i].link == props.href) {
                isPower = true;
                Com=React.lazy(()=>import(`../pages${props.href}`))
            }
        }
    }
    //Suspense  因为是异步加载  在还没有加载出来的时候执行的组件
    if (isPower && Com!=null) {
        return <Suspense fallback={<Loading />}>
            <Com/>
        </Suspense>
    }else{
        return <div>您的身份无此权限</div> 
    }
}
export default HOC;